package main

import (
	"flag"
	"fmt"
	"github.com/pborman/uuid"
	"github.com/upmio/horus-agent/hclient"
	"github.com/upmio/horus-agent/model"
	"sync"
	"time"
)

var (
	Pnum  int
	Pdata int
	wg    sync.WaitGroup
)

func init() {
	flag.IntVar(&Pnum, "pnum", 10, "")
	flag.IntVar(&Pdata, "Pdata", 100000, "")
	flag.Parse()
}

func getEventData(endpoint string) *model.DataPoint {
	event := &model.EventMetric{
		Eventid:     uuid.New(),
		EndPoint:    endpoint,
		Value:       "event value string",
		Metric:      "event.test",
		Level:       "testing",
		Tags:        "testid",
		CreateStamp: int64(time.Now().Unix()),
	}

	eventdata := &model.DataPoint{
		Persistence: true,
		Uuid:        uuid.New(),
		Type:        model.EVENT_DATA,
		DataObj:     event,
	}
	return eventdata
}

func produceEvent() {
	defer wg.Done()

	endpoint := uuid.New()
	fmt.Println("run  Metric product:", endpoint)
	for i := 0; i < Pdata; i++ {
		data := getEventData(endpoint)
		hclient.SendDataByQue(data)
		time.Sleep(1 * time.Second)
	}

	fmt.Println(endpoint, ":run ok")
}

func main() {

	hclient.RunInit(1000, 200)

	for i := 0; i < Pnum; i++ {
		wg.Add(1)
		go produceEvent()
	}

	wg.Wait()

}
